<template>
  <view>
    <u-tabbar
      :value="vuex_pathIndex"
      :fixed="true"
      :placeholder="true"
      :safe-area-inset-bottom="true"
      active-color="#FF5533"
      @change="tabChangeFn"
    >
      <u-tabbar-item text="首页">
        <text
          slot="active-icon"
          class="active-icon t-icon t-icon-shouyefill_tongyong_1"
        />
        <text
          slot="inactive-icon"
          class="active-icon t-icon t-icon-shouyestroke_tongyong_1"
        />
      </u-tabbar-item>
      <u-tabbar-item
        text="分类"
      >
        <text
          slot="active-icon"
          class="active-icon t-icon t-icon-fenleifill_tongyong_1"
        />
        <text
          slot="inactive-icon"
          class="active-icon t-icon t-icon-fenleistroke_tongyong_1"
        />
      </u-tabbar-item>
      <u-tabbar-item
        text="购物车"
      >
        <text
          slot="active-icon"
          class="active-icon t-icon t-icon-caigoudanfill_tongyong_1"
        />
        <text
          slot="inactive-icon"
          class="active-icon t-icon t-icon-caigoudanstroke_tongyong_1"
        />
      </u-tabbar-item>
      <u-tabbar-item text="订单">
        <text
          slot="active-icon"
          class="active-icon t-icon t-icon-dingdanfill_tongyong_1"
        />
        <text
          slot="inactive-icon"
          class="active-icon t-icon t-icon-dingdanstroke_tongyong_1"
        />
      </u-tabbar-item>
      <u-tabbar-item text="我的">
        <text
          slot="active-icon"
          class="active-icon t-icon t-icon-wodefill_tongyong_1"
        />
        <text
          slot="inactive-icon"
          class="active-icon t-icon t-icon-wodestroke_tongyong_1"
        />
      </u-tabbar-item>
    </u-tabbar>
  </view>
</template>

<script>
import { tdkUrl } from '@/common/common';
export default {
  name: 'Tabbar',
  data() {
    return {
      pagePaths: [
        '/shopIndex/shopIndex', //云采首页
        '/goodsGroup/goodsGroup/index', //分类
        '/purchaseOrder/index', //购物车
        // '/pages/order/index', //订单
        '/pages/order/moreOrder', //订单
        '/pages/myAccount/index' //我的
      ]
    }
  },
  mounted() {
    this.setPagePathsFn()
  },
  methods: {
    setPagePathsFn() {
      /*if (!this.vuex_loginStatus || (this.vuex_loginStatus && this.vuex_memberInfo && this.vuex_memberInfo.accountType == 20)) {
        this.pagePaths = [
          '/shopIndex/shopIndex', //云采首页
          '/goodsGroup/goodsGroup/index', //分类
          '/purchaseOrder/index', //购物车
          '/pages/order/index', //订单
          '/pages/myAccount/index' //我的
        ]
      }*/
      const pages = getCurrentPages()
      const curPagePath = pages[pages.length - 1].route
      this.$u.vuex('vuex_pathIndex', this.pagePaths.indexOf('/' + curPagePath))
    },
    tabChangeFn(index) {
      if (this.pagePaths[index] == '/purchaseOrder/index' && (!this.vuex_loginStatus || !this.vuex_loginStatus)) {
        const callbackUrl = this.pagePaths[index]
        // #ifdef MP-ALIPAY || MP-WEIXIN
        uni.navigateTo({
          url: `/login/login/codeLogin?type=my&callbackUrl=${callbackUrl}`
        })
        // #endif
        // #ifdef H5
        uni.redirectTo({
          url: `/login/login/mCodeLogin?type=my&callbackUrl=${callbackUrl}`
        })
        // #endif
      } else {
        this.$u.vuex('vuex_pathIndex', index)
        // #ifdef H5
        if (this.pagePaths[index] == '/shopIndex/shopIndex') {
          window.location.href = tdkUrl.develop
        } else if (this.pagePaths[index] == '/goodsGroup/goodsGroup/index') {
          window.location.href = tdkUrl.develop + '/category.html'
        } else {
          uni.redirectTo({ url: this.pagePaths[index] })
        }
        // #endif
        // #ifdef MP-ALIPAY || MP-WEIXIN
        uni.redirectTo({ url: this.pagePaths[index] })
        // #endif
      }
    }
  }
}
</script>

<style scoped>
.active-icon{
  width: 52rpx;
  height: 52rpx;
}
</style>
